package com.CGFrame.struts.action.gantt;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Company;
import com.CGFrame.struts.bean.category.CateModelBean;
import com.CGFrame.struts.bean.log.LogHistoryBean;

public class ModeladdunitAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String unitid=request.getParameter("ObjectID");
		String unittype=request.getParameter("Type");
		String catemodelid=request.getParameter("catemodelid");
		
		CateModelBean cmb=new CateModelBean(Integer.valueOf(catemodelid));
		String rs=cmb.addModelToUnit(unittype, Integer.valueOf(unitid));
		
		LogHistoryBean logBean = new LogHistoryBean();
		String regUserId = (String)request.getSession().getAttribute("RegUserID");
		logBean.saveByReguserId(regUserId, LogHistoryBean.ADD,"MODEL-"+cmb.getCatemodel().getCateModelName()+" used ", unittype, Integer.valueOf(unitid));
		
	//	request.setAttribute("Type", unittype);
	//	request.setAttribute("ObjectID", unitid);
		String path = "index.do?Type="+unittype+"&ObjectID="+unitid;
		ActionForward  forward = new ActionForward(path);
		forward.setRedirect(true);
		return forward;
	}
}
